package com.horoscope.astrology.zodiac.signs.free.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.horoscope.astrology.zodiac.signs.free.R
import com.horoscope.astrology.zodiac.signs.free.utils.HtmlToText

class AspectAdapter(private val mContext: Context) :
    RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    private val mData = ArrayList<String>()

    fun setData(list: ArrayList<String>) {
        mData.clear()
        mData.addAll(list)
        notifyDataSetChanged()

    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.item_aspects, parent, false)
        return ContentViewHolder(view)
    }

    override fun getItemCount(): Int {
        return mData.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        when (holder) {
            is ContentViewHolder -> {
                val str = mData[position]

                holder.title.text = HtmlToText.delHTMLTag(str)
                /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    holder.title.text = Html.fromHtml(str,0)
                }else{
                    holder.title.text = Html.fromHtml(str)
                }*/
            }
        }
    }

    inner class ContentViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val title = itemView.findViewById<TextView>(R.id.tv_aspect_2)
    }
}